package com.szh.mysobproject.viewmodel

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.PagingData
import androidx.paging.cachedIn
import com.szh.mysobproject.model.UserFollow
import com.szh.mysobproject.other.FollowState
import com.szh.mysobproject.paging.source.UserFollowOrFansPagingSource
import kotlinx.coroutines.flow.Flow


/**
 * @author : create by  szh
 * @date : 2022/7/11 9:34
 * @desc :粉丝viewModel
 */

class FollowOrFansViewModel : ViewModel() {

    fun loadUserFollowOrFansListByState(
        userId: String,
        followState: FollowState
    ): Flow<PagingData<UserFollow.UserFollowItem>> {
        return Pager(config = PagingConfig(30),
            pagingSourceFactory = {
                UserFollowOrFansPagingSource(userId, followState)
            }).flow.cachedIn(viewModelScope)
    }
}